package pro.lingwu.station.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import pro.lingwu.station.dto.db.BusNo;
import pro.lingwu.station.dto.db.Station;
import pro.lingwu.station.service.BusNoService;

import javax.validation.Valid;

/**
 * @author @lingwu
 * @date created in 2021/11/16
 */
@Api(tags = "BusNo")
@RestController
public class BusNoController {

    private final BusNoService service;

    public BusNoController(BusNoService service) {
        this.service = service;
    }

    @ApiOperation(value = "增加车次")
    @PostMapping("/bus-no")
    ResponseEntity<?> addBusNo(@Valid BusNo busNo){
        service.addBusNo(busNo);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation(value = "获取所有车次(某个范围)的信息")
    @GetMapping("/bus-no")
    ResponseEntity<?> getBusNo(int start, int size, BusNo busNo, String startS, String endS){
        return ResponseEntity.ok(service.getAllBusNo(start, size, busNo, startS, endS));
    }

    @ApiOperation(value = "删除一个车次")
    @PostMapping("/bus-no/{id}")
    ResponseEntity<?> rmBusNo(@PathVariable String id){
        service.rmBusNo(id);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation(value = "更新车次信息")
    @PutMapping("/bus-no/{id}")
    ResponseEntity<?> updateBusNo(@PathVariable String id, BusNo busNo){
        busNo.setId(id);
        service.updateBusNo(busNo);
        return ResponseEntity.ok("ok");
    }
    
}
